home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / calllog.c < prev    next >
C/C++ Source or Header  |  1995-09-12  |  7KB  |  294 lines

  1. /*
  2. *                               calllog.c
  3. *
  4. * handles call log of Citadel-86
  5. */
  6. #include "ctdl.h"
  7. /*
  8. *                               history
  9. *
  10. * 88Sep02 HAW  Download/Upload log.
  11. * 86Mar07 HAW  New users and .ts signals.
  12. * 86Feb09 HAW  System up and down times.
  13. * 86Jan22 HAW  Set extern var so entire system knows baud.
  14. * 85Dec08 HAW  Put blank lines in file.
  15. * 85Nov?? HAW  Created.
  16. */
  17. /*
  18. *                               Contents
  19. *
  20. *       logMessage()            Put out str to file.
  21. *       fileMessage()           Handles file messages
  22. */
  23. struct timeData
  24.   {
  25.   int   y, d, h, m;
  26.   char  month[5];
  27.   label person;
  28.   char  newuser;
  29.   char  evil;
  30.   char  chat;
  31.  
  32.   };
  33. struct timeData lgin;
  34. extern CONFIG      cfg;
  35. extern logBuffer   logBuf;
  36. extern PROTO_TABLE Table[];
  37. extern aRoom       roomBuf;
  38. extern long byteRate;
  39. extern MessageBuffer     msgBuf;
  40. extern char        *WRITE_ANY, *READ_ANY;
  41. extern char lastuser[28];              /* save for console display */
  42. static char CallFn[80] = "";    /* can't use SYS_FILE here I fear */
  43. static char CallCrash = FALSE;
  44. static char *curBaud = NULL;
  45. char FileTransStat;           /* status of file transgers */
  46.  
  47. /*
  48. * logMessage()
  49. *
  50. * This function puts messages in the CALLLOG.SYS file depending on a number
  51. * of different events and conditions.
  52. */
  53. void logMessage(int val,char *str,char sig)
  54.   {
  55.   static int oldDay = 0;
  56.   FILE *fd;
  57.   int  yr, dy, hr, mn;
  58.   char *mon, buf[100];
  59.   char *format = "%s %s @ %d:%02d%s";
  60.   char *SaveName = "callsave.sys";
  61.   if (cfg.BoolFlags.debug)
  62.     splitF(NULL,"logMessage(%d, %s, %x)\n",val,str,sig);
  63.  
  64.   if (CallCrash) return;
  65.   if (val == BAUD || val == DOOR_RETURN)
  66.     {
  67.     byteRate = atoi(str) / 10;
  68.  
  69.     }
  70.   if (cfg.Audit == 0) return;
  71.   makeAuditName(CallFn, "calllog.sys");
  72.   getCdate(&yr, &mon, &dy, &hr, &mn);
  73.   switch (val)
  74.     {
  75.     case FIRST_IN:
  76.     if (cfg.BoolFlags.IsDoor)break;
  77.     oldDay = dy;
  78.     sPrintf(buf, format, "System brought up", formDate(), hr, mn,
  79.     "");
  80.     CallMsg(CallFn, buf);
  81.     break;
  82.     #ifndef NO_DOORS
  83.     case DOOR_RETURN:
  84.     oldDay  = dy;
  85.     curBaud = str;
  86.     if ((fd = safeopen(SaveName, READ_ANY)) != NULL)
  87.       {
  88.       fread(&lgin, sizeof lgin, 1, fd);
  89.       fclose(fd);
  90.       unlink(SaveName);
  91.  
  92.       }
  93.     else printf("No luck with %s.", SaveName);
  94.     break;
  95.     #endif
  96.     case CRASH_OUT:
  97.     case LAST_OUT:
  98.     if (cfg.BoolFlags.IsDoor)return;
  99.     sPrintf(buf, format, "System brought down", formDate(), hr, mn,
  100.     (val == CRASH_OUT) ? " (crash exit!)" : "");
  101.     CallMsg(CallFn, buf);
  102.     return;
  103.     #ifndef NO_DOORS
  104.     case DOOR_OUT:
  105.     if ((fd = safeopen(SaveName, WRITE_ANY)) != NULL)
  106.       {
  107.       fwrite(&lgin, sizeof lgin, 1, fd);
  108.       fclose(fd);
  109.  
  110.       }
  111.     else printf("No luck with %s.", SaveName);
  112.     break;
  113.     #endif
  114.     case BAUD:
  115.     curBaud     = str;
  116.     lgin.person[0] = 0;
  117.     goto datestuff;             /* ACK!  ACK!  ACK! */
  118.     case L_IN:
  119.     lgin.newuser = sig;
  120.     strCpy(lgin.person, str);
  121.     lgin.evil  = ' ';
  122.     lgin.chat  = ' ';
  123.     case INTO_NET:
  124.     datestuff:
  125.     lgin.y = yr;
  126.     lgin.d = dy;
  127.     lgin.h = hr;
  128.     lgin.m = mn;
  129.     strcpy(lgin.month, mon);
  130.     break;
  131.     case TRIED_CHAT:
  132.     lgin.chat  = 'C';
  133.     break;
  134.     case EVIL_SIGNAL:
  135.     lgin.evil  = 'E';
  136.     break;
  137.     case BADWORDS_SIGNAL:
  138.     lgin.evil  = 'B';
  139.     break;
  140.     case CARRLOSS:
  141.     homeSpace();        /* back to our regular lair, don't break! */
  142.     case L_OUT:
  143.     /*
  144.     * curBaud's length 0 means the user is on the system console.
  145.     * So this code means "If no person is logged in and
  146.     * Anonymous session logging is off OR the anonymous user
  147.     * was at the system console ..."
  148.     */
  149.     if( curBaud == NULL ) curBaud  = "";  /* string of length 0 */
  150.     if (!lgin.person[0] &&
  151.     !(cfg.BoolFlags.AnonSessions && strLen(curBaud) != 0))
  152.       {
  153.       curBaud = "";
  154.       break;
  155.  
  156.       }
  157.     if (oldDay != dy)
  158.     CallMsg(CallFn, "");
  159.     sPrintf(buf,
  160.     "%-22s: %2d%s%02d %2d:%02d - %2d:%02d (%s)",
  161.     (strLen(lgin.person)) ? lgin.person : "<No Login>",
  162.     lgin.y, lgin.month, lgin.d, lgin.h, lgin.m,
  163.     hr, mn, (curBaud == NULL || strLen(curBaud) == 0) ?
  164.     "sysConsole" : curBaud);
  165.     if (lgin.newuser) sPrintf(lbyte(buf), " %c", lgin.newuser);
  166.     if (sig != 0) sPrintf(lbyte(buf), " %c", sig);
  167.     if (lgin.evil != ' ') sPrintf(lbyte(buf), " %c", lgin.evil);
  168.     if (lgin.chat != ' ') sPrintf(lbyte(buf), " %c", lgin.chat);
  169.     CallMsg(CallFn, buf);
  170.     if( strLen(lgin.person) )strcpy(lastuser,lgin.person);
  171.     lgin.person[0] = 0;
  172.     oldDay = dy;
  173.     if (val == CARRLOSS) curBaud = NULL;
  174.     goto datestuff;
  175.     break;
  176.     case OUTOF_NET:
  177.     if (cfg.Audit == 1)
  178.       {
  179.       sPrintf(buf,
  180.       "System in network mode: %d%s%02d %2d:%02d - %2d:%02d",
  181.       lgin.y, lgin.month, lgin.d, lgin.h, lgin.m, hr, mn);
  182.       CallMsg(CallFn, buf);
  183.  
  184.       }
  185.     break;
  186.     default:
  187.     splitF(NULL," Bad Call to logMessage(%ld, %s,%d)\n",val,str,(int)sig);
  188.  
  189.     }
  190.  
  191.   }
  192. /*
  193. * fileMessage()
  194. *
  195. * This function handles the upload/download file log.
  196. */
  197. void fileMessage(char mode, char *fn, char IsDL, int protocol, long size)
  198.   {
  199.   long    work, hours, mins;
  200.   static label  LastActive = "";
  201.   char    logfn[100];
  202.   int             yr, dy, hr, mn;
  203.   char    *mon, *pr, buf[100];
  204.   static struct timeData fData;
  205.   if (protocol == ASCII || cfg.Audit == 0)
  206.   return;
  207.   makeAuditName(logfn, "filelog.sys");
  208.   getCdate(&yr, &mon, &dy, &hr, &mn);
  209.   switch (mode)
  210.     {
  211.     case FL_START:
  212.     startTimer(USER_TIMER);
  213.     fData.y = yr;
  214.     fData.d = dy;
  215.     fData.h = hr;
  216.     fData.m = mn;
  217.     strcpy(fData.month, mon);
  218.     break;
  219.     case FL_SUCCESS:
  220.     case FL_FAIL:
  221.         FileTransStat = mode;
  222.     case FL_EX_END:
  223.     if (strCmpU(LastActive, logBuf.lbname) != SAMESTRING)
  224.       {
  225.       sPrintf(buf, "\n%s on %d%s%02d @ %ld:", logBuf.lbname, yr, mon, dy,
  226.       byteRate * 10);
  227.       CallMsg(logfn, buf);
  228.       strCpy(LastActive, logBuf.lbname);
  229.  
  230.       }
  231.     work = chkTimeSince(USER_TIMER);
  232.     hours = work / 3600;
  233.     work -= (hours * 3600);
  234.     mins  = work / 60;
  235.     work -= (mins * 60);
  236.     if (protocol > TOP_PROTOCOL)
  237.     pr = FindProtoName(protocol);
  238.     else
  239.     pr = Table[protocol].GenericName;
  240.     if (mode == FL_EX_END)
  241.       {
  242.       sPrintf(buf,
  243.       "%2cFollowing files %c %s via %s %d:%02d - %d:%02d (%ld:%02ld:%02ld):",
  244.       ' ', (IsDL) ? 'D' : 'U', roomBuf.rbname,
  245.       pr,
  246.       fData.h, fData.m, hr, mn,
  247.       hours, mins, work);
  248.       CallMsg(logfn, buf);
  249.       CallMsg(logfn, msgBuf.mbtext);
  250.  
  251.       }
  252.     else
  253.       {
  254.       sPrintf(buf,
  255.       "%2c%s (%ld) %s %s: %d:%02d - %d:%02d (%ld:%02ld:%02ld) %s. %s",
  256.       ' ', fn, size, (IsDL) ? "D" : "U", roomBuf.rbname,
  257.       fData.h, fData.m, hr, mn,
  258.       hours, mins, work,
  259.       pr,
  260.       (mode == FL_FAIL) ? "(FAILED)" : "");
  261.       CallMsg(logfn, buf);
  262.  
  263.       }
  264.     break;
  265.  
  266.     }
  267.  
  268.   }
  269. /*
  270. * CallMsg()
  271. *
  272. * This function is a generic message writing mechanism.  Given a filename, it
  273. * appends the given message to the end of said file.
  274. */
  275. void CallMsg(char *fn, char *str)
  276.   {
  277.   FILE  *fd;
  278.   extern char *A_C_TEXT;
  279.   if ((fd = safeopen(fn, A_C_TEXT)) != NULL)
  280.     {
  281.     fprintf(fd, "%s\n", str);
  282.     fclose(fd);
  283.  
  284.     }
  285.   else
  286.     {
  287.     CallCrash = TRUE;
  288.     printf("Failure: filename is %s", fn);
  289.     /*  crashout("CallMsg error!");  */
  290.  
  291.     }
  292.  
  293.   }
  294.